def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

n = int(input())

if 1000 <= n <= 9999:
    digits = [int(d) for d in str(n)]
    max_prime = 0
    
    for i in range(len(digits)):
        candidate = int("".join(map(str, digits[:i+1])))
        if is_prime(candidate) and candidate > max_prime:
            max_prime = candidate
    
    print(max_prime if max_prime > 0 else 0)
else:
    print(0)
